<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>找护工</title>
    <!-- Path to Framework7 Library CSS-->
    <link rel="stylesheet" href="../css/framework7.ios.min.css">
    <link rel="stylesheet" href="../css/framework7.ios.colors.min.css">
    <!-- Path to your custom app styles-->
    <link rel="stylesheet" href="../css/my-app.css">
    <link rel="stylesheet" href="../css/ekang.css"/>
    <style type="text/css">
        body {
            background-color: #fff;
        }
        /*.picker-item{*/
            /*text-align: hidden;*/
        /*}*/
        li {
            width: 100%;
            height: 50px;
            margin-top: 10px;
            background-color: #fff;
            border-top: 1px solid #dddddd;
            border-bottom: 1px solid #dddddd;
            list-style-type: none;
        }

        .li-title {
            position: absolute;
            color: #333333;
            font-size: 14px;
            left: 12px;
            line-height: 50px;
            /*font-weight: bold;*/
        }

        ::-webkit-input-placeholder { color: #b3b3b3; }
        input:-moz-placeholder { color: #b3b3b3; }

        .li-text {
            position: absolute;
            color: #b3b3b3;
            border: none;
            outline: none;
            font-size: 15px;
            line-height: 45px;
            right: 0;
            width: 60%;
            text-align: right;
            background-color: rgba(102, 102, 102, 0);
        }

        .li-title-detail {
            position:absolute;
            color: #b3b3b3;
            border: none;
            outline: none;
            font-size: 15px;
            right: 0;
            text-align: left;
            /*background-color:#009688;*/
            width: 94%;
            height: 79px;
            left: 10px;
            top: 5px;
        }

        .icon-right {
            background: url(../img/right_24.png) no-repeat 98% center transparent;
            background-color: #fff;
            background-size: 12px 12px;
        }

        .tabs-choose {
            /*height: 50px;*/
            line-height: 50px;
            position: absolute;
            background-color: #ffffff;
            right: 25px;
            color: #333333;
        }

        .tabs-choose div {
            background-origin: content-box;
            font-size: 14px;
            text-align: right;
        }
    </style>
</head>
<body>

<div class="views tabs toolbar-through">
    <!--导航条-->
    <!-- Second view (for second wrap)-->
    <div id="view" class="view view-main tab active">
        <!-- We can make with view with navigation, let's add Top Navbar-->
        <div class="navbar">
            <div class="navbar-inner" style="background-color: #38a16d">
                <div class="left" id="back">
                    <a href="#" class="back link">
                        <i class="icon icon-back color-white" style="color: white"></i>
                        <span style="color: white">返回</span>
                    </a>
                </div>
                <div class="center sliding" style="color: white">找护工</div>
            </div>
        </div>

        <div class="pages navbar-through">
            <div data-page="index-2" class="page page-on-center">
                <div class="page-content">
                    <div>
                        <ui>
                            <li id="hospitalDetail" style="margin-top: 0;border-top: none" class="icon-right">
                                <span class="li-title">选择医院科室</span>
                                <div id="departmentDetail" class="tabs-choose text-center"></div>
                            </li>
                            <li class="icon-right">
                                <span class="li-title">护理天数</span>
                                <!--<div class="tabs-choose text-center ">选择护理天数</div> id="creat-picker"-->
                                <input placeholder="请输入护理天数" type="number" id="nurse_day" class="tabs-choose text-center" style="text-align:right;border: none;background-color: rgba(0, 0, 0, 0);line-height: 45px">

                            </li>
                            <li class="icon-right">
                                <span class="li-title">开始陪护时间</span>
                                <input placeholder="点击选择" type="datetime-local" id="nures_time" class="tabs-choose text-center" style="text-align:right;border: none;background-color: rgba(0, 0, 0, 0);line-height: 45px">
                            </li>
                            <li class="icon-right" id="choosePeople">
                                <span class="li-title">就诊患者</span>
                                <div class="tabs-choose text-center" id="user_name">点击选择</div>
                            </li>
                            <li class="icon-right">
                                <span class="li-title">患者年龄</span>
                                <!--<div  class="tabs-choose text-center" id="sex_text">点击选择</div>-->
                                <input placeholder="请输入患者年龄" type="text" id="people_age" class="tabs-choose text-center" style="text-align:right;border: none;background-color: rgba(0, 0, 0, 0);line-height: 45px">

                            </li>
                            <li>
                                <span class="li-title">备用联系人</span>
                                <input type="number" id="mobile" placeholder="请输入备用联系人手机号" class="li-text"/>
                            </li>
                            <li class="icon-right">
                                <span class="li-title">诊疗金</span>
                                <div  class="tabs-choose text-center" id="diagnosis_money">点击选择</div>
                            </li>
                            <li style="position:relative;height: 89px">
                                <textarea id="disease_detail" class="li-title-detail" placeholder="请简单的描述患者的病情或就诊经历"></textarea>
                            </li>
                        </ui>
                        <p class="message" style="font-size: 12px;color: #333333">预约护理的服务费价格根据护理天数而定，价格为</br>200/天</p>
                        <br/>
                    </div>

                </div>
            </div>
        </div>
        <div style="position: fixed;display: flex;height: 49px;width: 100%;background-color: #393d3b;bottom: 0">
            <div style="position: absolute;left: 10px;line-height: 49px;font-size: 13px;color: #fff">服务费：<span id="money_num"></span>元</div>
            <div style="position: absolute;right: 0;width: 105px;height: 49px;background-color: #26d086;font-size: 16px;color: #fff;text-align: center;line-height: 49px" id="immediate">立即预约</div>
        </div>
    </div>
</div>
<script type="text/javascript" src="../js/framework7.min.js"></script>
<script type="text/javascript" src="../js/my-app.js"></script>
<script src="../js/jquery-1.10.2.js"></script>
<script src="../js/ekang.js"></script>
<script src="../js/jquery.cookie.js"></script>
<script>

    $(function () {

        // 诊疗金数据
        var diagName;
        var diagId;

        var department_id;
        var hospital_id;

        // 选择医院科室
        if($.cookie("hospital_name")){
            $('#departmentDetail').html($.cookie("hospital_name")+$.cookie("department_name"));

            hospital_id = $.cookie("hospital_id");
            department_id = $.cookie("department_id");

        }else{
            $('#departmentDetail').html("请选择医院科室");
        }
//        $(document).focus(function(){
//            //alert(123)
//            $('#content-picker').show()
//        })
        // 用户
        if($.cookie("username")){
            $('#user_name').html($.cookie("username"));
        }

        // 诊疗金
        if($.cookie("dia_name")){
            diagName = $.cookie("dia_name");
            diagId = $.cookie("dia_id");
            $('#diagnosis_money').html(diagName+"元诊疗金");
            $('#money_num').html(parseInt($('#money_num').text())-parseInt(diagName));
//            // 删除本地保存
//            $.cookie('dia_name', "", { expires: 7,path: '/' });
//            $.cookie('dia_id', "", { expires: 7,path: '/' });
        }else{
            $('#diagnosis_money').html();
        }

        $('#nurse_day').keyup(function () {
            $('#money_num').html(parseInt($('#money_num').text())*parseInt($(this).val()));
        });

        var app = {
            subOrder: function () {
                $.ajax({
                    type: 'GET',
                    url: textUrl + '/diagnosis/submitOrder/',
                    data: {         // 需要于客户端同步

                        family_id : $.cookie("userId"),
                        hospital_id : $.cookie("hospital_id"),
                        department_id : $.cookie("department_id"),
                        appointment_type : '5',
                        type : '4',
                        uid : $.cookie("local_userId"),
                        appointment_time: $.myTime.DateToUnix($('#nures_time').val()),
                        mobile : $('#mobile').val(),
                        disease : $('#disease_detail').val(),
                        coupon_id : diagId,
                        stay_days : $('#nurse_day').val(),
                        age : $('#people_age').val()

                    },
                    dataType: 'jsonp',
                    jsonp: 'callback',
                    success: function (result) {
                        if (result.ret == 0) {
                            $.cookie('department_id', "", { expires: 7,path: '/' });
                            $.cookie('department_name', "", { expires: 7,path: '/' });
                            $.cookie('hospital_name', "" , { expires: 7,path: '/' });
                            $.cookie('hospital_id', "", { expires: 7,path: '/' });
                            var order = result.data.order_id;
                            location.href = "../hospital_nurse/nurse_payorder.html?order_id="+order;
                        } else {
                            alert(result.msg);
                        }
                    }
                });
            },
            getPrice: function () {
                $.ajax({
                    type: 'GET',
                    url: textUrl + '/diagnosis/getPrice/',
                    data: {         // 需要于客户端同步
                        hospital_id : hospital_id,
                        department_id : department_id,
                        appointment_type : '5',
                        type : '4',
                        uid : $.cookie("local_userId")
                    },
                    dataType: 'jsonp',
                    jsonp: 'callback',
                    success: function (result) {
                        if (result.ret == 0) {

                            $('#money_num').html(result.data.nurse_price);

                            if($('#nurse_day').val()){
                                $('#money_num').html(parseInt($('#money_num').text())*parseInt($('#nurse_day').val()));
                            }

                            if($.cookie("dia_name")){
                                diagName = $.cookie("dia_name");
                                diagId = $.cookie("dia_id");
                                $('#diagnosis_money').html(diagName+"元诊疗金");
                                $('#money_num').html(parseInt($('#money_num').text())-parseInt(diagName));
                                // 删除本地保存
                                $.cookie('dia_name', "", { expires: 7,path: '/' });
                                $.cookie('dia_id', "", { expires: 7,path: '/' });
                            }else{
                                $('#diagnosis_money').html();
                            }
                        }else {
                            alert(result.msg);
                        }
                    }
                });
            }
        };

        app.getPrice();

        // 就诊人
        $('#choosePeople').on('click', function () {
            location.href = "../addPeople/contactPeople.html"
        });
        // 诊疗金
        $('#diagnosis_money').on('click', function () {
            var  money;
            if(diagName){
                money = parseInt($('#money_num').text())+parseInt(diagName);
            }else{
                money = $('#money_num').text();
            }
            $('#money_num').html(money);

            location.href = "../myCenter/diagnosis_money.html?allMoney="+money;
        });

        $('#hospitalDetail').on('click', function () {
            location.href = "../hospitalInformation/hospitalList.html";
        });
        // 声明f7
        var myApp = new Framework7();
        var $$ = Dom7;
        // 选择日期
        var today = new Date();

        //-----------------陪诊时间
        $$('#creat-picker').on('click', function () {

            if ($$('.picker-modal.modal-in').length > 0) {
                myApp.closeModal('.picker-modal.modal-in');
            }
            myApp.pickerModal(
                    '<div class="picker-modal" id="content-picker">' +
                    '<div class="toolbar">' +
                    '<div class="toolbar-inner">' +
                    '<div class="left"></div>' +
                    '<div class="right"><a href="#" class="close-picker">关闭</a></div>' +
                    '</div>' +
                    '</div>' +
                    '<div class="picker-modal-inner" style="width: 96%;left: 0">' +
                    '<div class="content-block">' +
                        // 数据
                    '<div class="time-content" style="margin-top: -20px">'+
                    '</div>'+

                    '</div>' +
                    '</div>' +
                    '</div>'
            )

            var pickerInline = myApp.picker({
                input: '#nures_time',
                container: '.time-content',
                toolbar: false,
                rotateEffect: true,

                value: [today.getFullYear(),today.getMonth()+1, today.getDate(),  today.getHours(), (today.getMinutes() < 10 ? '0' + today.getMinutes() : today.getMinutes())],

                onChange: function (picker, values, displayValues) {

                    var daysInMonth = new Date(picker.value[2], picker.value[2]*1 + 1, 0).getDate();
                    if (values[1] > daysInMonth) {
                        picker.cols[1].setValue(daysInMonth);
                    }
                },

                formatValue: function (p, values, displayValues) {
                    return displayValues[0] + ' ' + values[1] + ', ' + values[2] + ' ' + values[3] + ':' + values[4];
                },

                cols: [
                    // Years
                    {
                        values: (function () {
                            var arr = [];
                            for (var i = 1950; i <= 2030; i++) { arr.push(i); }
                            return arr;
                        })(),
                    },
                    // Months
                    {
                        values: ('1 2 3 4 5 6 7 8 9 10 11 12').split(' '),
                        displayValues: ('1 2 3 4 5 6 7 8 9 10 11 12').split(' '),
                        textAlign: 'left'
                    },
                    // Days
                    {
                        values: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],
                    },
                    // Space divider
                    {
                        divider: true,
                        content: '  '
                    },
                    // Hours
                    {
                        values: (function () {
                            var arr = [];
                            for (var i = 0; i <= 23; i++) { arr.push(i); }
                            return arr;
                        })(),
                    },
                    // Divider
                    {
                        divider: true,
                        content: ':'
                    },
                    // Minutes
                    {
                        values: (function () {
                            var arr = [];
                            for (var i = 0; i <= 59; i++) { arr.push(i < 10 ? '0' + i : i); }
                            return arr;
                        })(),
                    }
                ]
            });

            pickerInline;
        });

        // 选择性别
        $$('#user_sex').on('click', function () {
            var buttons = [
                {
                    text: '男',
                    bold: true,
                    onClick: function () {
                        $('#sex_text').html("男");
                    }
                },
                {
                    text: '女',
                    onClick: function () {
                        $('#sex_text').html("女");
                    }
                },
                {
                    text: '取消',
                    color: 'red'
                }
            ];
            myApp.actions(buttons);

        });

        // 立即预约
        $('#immediate').on('click', function () {
            if(!$('#nurse_day').val()){
                alert("请填写护理天数");
                return;
            }
            if($('#nurse_day').val() >= 32){
                alert("陪护时间最多31天");
                return;
            }
            if(!$('#nures_time').val()){
                alert("请选择陪护时间");
                return;
            }
            if($('#user_name').text()=='点击选择'){
                alert('点击选择');
            }
            if($('#people_age').val()==''){
                alert('请填写年龄')
                return;
            }
            if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test($('#mobile').val()))){
                alert("请输入正确的手机号");
                document.mobileform.mobile.focus();
                return false;
            }
            if($('#disease_detail').val().length == 0){
                alert("请简单的描述患者的病情或就诊经历");
                return;
            }

            app.subOrder();
        });

        $('#back').click(function () {
            history.back();
        });
    });

</script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript"></script>
<script src="../js/weixin2.js"></script>
<style>
    .picker-item{
        text-overflow: hidden;
    }
</style>
</body>
</html>